var prefix = api + "/admin/tenant";

$(function () {

  var options = {
    url: api + "/scabpm/bpm/my/applyTaskList",
    listType: 'bpm',
    updateUrl: '/pages/bpm/applyHistory/edit',
    removeUrl:  api + '/scabpm/bpm/instance/delete?id={id}',
    method: 'post',
    modalName: "申请历史",
    columns: [
      {
        field: 'subject',
        title: '流程标题',
      },
      {
        field: 'defName',
        title: '流程名称',
      },
      {
        field: 'status',
        title: '状态',
        align: 'center',
        formatter: function (value, row, index) {
          return statusDict(value)
        }
      },
      {
        field: 'createTime',
        title: '创建时间',
      }, {
        field: 'creator',
        title: '创建人',
      },
      {
        field: 'endTime',
        title: '完成时间',
      },
      {
        field: 'duration',
        title: '持续时间',
      },
      {
        title: '操作',
        formatter: function (value, row, index) {
          var actions = [];
          var name = '申请历史【'+row.defName+'】'
          actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editFullBpm(\'' + row.id + '\',\'' + name + '\')"><i class="fa fa-edit"></i>详情</a> ');
          return actions.join('');
        }
      }]
  };
  $.table.init(options);
});

function statusDict(item){
  var dict = {
    'running': {text:'运行中',color:'text-success'},
    'end': {text:'终止',color:'text-default'},
    'manualend': {text:'人工终止',color:'text-danger'},
    'revoke': {text:'撤销',color:'text-danger'}
  }
  return '<i class="fa '+(dict[item] ? dict[item].color : '')+'">'+(dict[item] ? dict[item].text : item)+'</i>'
}

function remove(id) {
  table.set();
  $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗？", function () {
    var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
    $.operate.post(url,{},function(result){
      if (result.isOk){
        $.modal.msgSuccess(result.msg == null ? '操作成功' : result.msg);
        $.table.refresh();
      }else{
        $.modal.alertError(result.msg);
      }
      $.modal.closeLoading();
    });
  });
}